package com.timmy.test1;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

/**
 * Created by timmy on 2020/5/8.
 */

public class DialogFactory {
    public static void destoryDialog(Dialog paramDialog) {
        dismissDialog(paramDialog);
    }

    public static void dismissDialog(Dialog paramDialog) {
        if (paramDialog != null && paramDialog.isShowing())
            paramDialog.cancel();
    }

    public static Dialog showCustomDialog(Activity paramActivity, View paramView) {
        Dialog dialog = new Dialog((Context) paramActivity, R.style.MenuDialogStyle);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setContentView(paramView);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.dimAmount = 0.8F;
        window.setGravity(17);
        window.setAttributes(layoutParams);
        return dialog;
    }

    public static Dialog showCustomDialog3(Activity paramActivity, View paramView) {
        Dialog dialog = new Dialog((Context) paramActivity, R.style.MenuDialogStyle);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setContentView(paramView);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.width = (int) (App.SCREEN_WIDTH * 0.8D);
        window.setDimAmount(0.8F);
        window.setGravity(17);
        window.setAttributes(layoutParams);
        return dialog;
    }

    public static void showDialog(Dialog paramDialog) {
        if (paramDialog != null && !paramDialog.isShowing())
            if (paramDialog.getContext() instanceof Activity) {
                if (!((Activity) paramDialog.getContext()).isFinishing()) {
                    paramDialog.show();
                    return;
                }
            } else {
                paramDialog.show();
            }
    }

    public static Dialog showMenuDialog(Activity paramActivity, View paramView) {
        Dialog dialog = new Dialog((Context) paramActivity, R.style.MenuDialogStyle);
        dialog.setContentView(paramView);
        Window window = dialog.getWindow();
        (window.getAttributes()).width = App.SCREEN_WIDTH;
        window.setGravity(80);
        window.setWindowAnimations(R.style.MenuDialogAnimation);
        return dialog;
    }

    public static Dialog showTopMenuDialog(Activity paramActivity, View paramView) {
        Dialog dialog = new Dialog((Context) paramActivity, R.style.MenuDialogStyle);
        dialog.setContentView(paramView);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.width = App.SCREEN_WIDTH;
        layoutParams.height = -2;
        window.setGravity(48);
        dialog.show();
        return dialog;
    }

    public static Dialog showTopMenuDialog(Activity paramActivity, View paramView1, View paramView2) {
        Dialog dialog = new Dialog((Context) paramActivity, R.style.MenuDialogStyle);
        dialog.setContentView(paramView1);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.width = App.SCREEN_WIDTH;
        layoutParams.height = -2;
        int[] arrayOfInt = new int[2];
        paramView2.getLocationOnScreen(arrayOfInt);
        layoutParams.y = arrayOfInt[1] + paramView2.getHeight();
        window.setGravity(48);
        dialog.show();
        return dialog;
    }
}